<template>
  <div>
    <div class="row-header">
      <el-form :model="form" ref="form" label-width="50px" inline>
        <el-form-item label=" " prop="loginName">
          <el-autocomplete class="inline-input" v-model="form.loginName"
                           :fetch-suggestions="querySearch" :trigger-on-focus="false"
                           placeholder="请输入代理账号" style="width: 240px;"></el-autocomplete>
        </el-form-item>
        <el-form-item label=" " prop="cardNum">
          <el-input v-model.trim="form.cardNum" placeholder="请输入业务号码" clearable style="width: 240px;"></el-input>
        </el-form-item>
        <el-form-item label=" " prop="rechargeAmount" :rules="{
          pattern: /^[1-9]\d*$/, message: '连续充值次数只能输入正整数', trigger: 'blur'
        }">
          <el-input size="small" placeholder="请输入连续充值次数" v-model="form.rechargeAmount" clearable style="width: 240px;"></el-input>
        </el-form-item>
        <el-form-item label=" " prop="transactionId" v-if="roleChar=='OEM_ADMIN'||roleChar=='OEM_OTHER'">
          <el-input v-model="form.transactionId" style="width: 240px;" placeholder="请输入交易流水号"></el-input>
        </el-form-item>
        <el-form-item label=" " prop="accountId" v-if="roleChar=='OEM_ADMIN'">
          <el-select size="small" v-model="form.accountId" placeholder="请选择通道名称" style="width: 240px;">
            <el-option v-for="item in accountOptions" :key="item.value" :label="item.label"
                       :value="item.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label=" " prop="dictStatus">
          <el-select size="small" v-model="form.dictStatus" placeholder="请选择订单状态" style="width: 240px;">
            <el-option v-for="item in dictStatusSelect" :key="item.value" :label="item.label"
                       :value="item.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label=" " prop="setMealHeadId">
          <el-select size="small" v-model="form.setMealHeadId" @change="initSetMealList" placeholder="请选择套餐大类" style="width: 240px;">
            <el-option v-for="item in setMealHeadOptions" :key="item.value" :label="item.label"
                       :value="item.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label=" " prop="setMealId">
          <el-select size="small" v-model="form.setMealId" placeholder="请选择套餐小类" style="width: 240px;">
            <el-option v-for="item in setMealOptions" :key="item.value" :label="item.label"
                       :value="item.value"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label=" " prop="dictIsPreStorage">
          <el-select size="small" v-model="form.dictIsPreStorage" placeholder="请选择是否次月生效" style="width: 240px;">
            <el-option v-for="item in dictIsPreStorageOptions" :key="item.value" :label="item.label"
                       :value="item.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label=" " prop="insertTime">
          <el-date-picker class="select" v-model="form.insertTime" type="daterange" align="right" unlink-panels
                          range-separator="至" start-placeholder="提交开始日期" end-placeholder="提交结束日期" value-format="yyyy-MM-dd" ></el-date-picker>
        </el-form-item>
      </el-form>
      <div class="row-form-btn">
        <el-button size="small" type="shenda" icon="el-icon-search" @click="current=1,search()">查询</el-button>
        <el-button size="small" type="shenda" icon="el-icon-refresh-right" @click="clearForm('form')">重置</el-button>
        <el-button size="small" type="shenda" icon="el-icon-download" @click="exlDownload">导出</el-button>
        <el-button size="small" type="shenda" icon="el-icon-download" v-has="'exportFirstAgentProfit'" @click="exploreProfitDialog= true">导出一级代理利润</el-button>
      </div>
    </div>
    <div class="split-line"></div>
    <div class="el-main">
      <el-button type="shenda" size="small" icon="el-icon-refresh" @click="refreshPage">刷新数据</el-button>
      <div class="row-block-ddd" v-has="'oemOrderStaticsPower'"  :style="{'overflow-x':$store.state.app.screenWidth<992?'scroll':'auto',width:$store.state.app.screenWidth<992?'100%':'auto'}">
        <div class="row_top_item">
          <el-button type="shenda" round size="small"><b>订单数：</b><span class='btn_text'>{{ orderCount }}</span></el-button>
        </div>
        <div class="row_top_item">
          <el-button type="shenda" round size="small"><b>销售金额：</b><span class='btn_text'>{{ priceSum }}</span></el-button>
        </div>
        <div class="row_top_item">
          <el-button type="shenda" round size="small"><b>成本：</b><span class='btn_text'>{{ mineCostSum }}</span></el-button>
        </div>
        <div class="row_top_item">
          <el-button type="shenda" round size="small"><b>利润：</b><span class='btn_text'>{{ profitForAgentSum }}</span></el-button>
        </div>
        <el-button type="shendaWarning" size="small" @click="changeAllStatus" v-show="form.loginName&&roleChar=='OEM_ADMIN'">所有订单</el-button>
        <el-button type="shendaSuccess" size="small" @click="changeSectionStatus" v-show="form.loginName&&roleChar=='OEM_ADMIN'">直属订单</el-button>
      </div>
      <el-table :data="tableData" v-loading.fullscreen="tableLoading" :header-cell-style="{ 'background':$store.state.app.tableBgColor,'color':'#606266' }" class="row-main-table" tooltip-effect="dark"
                element-loading-text="拼命加载中" element-loading-spinner="el-icon-loading" element-loading-background="rgba(0, 0, 0, 0.2)" ref="table">
        <el-table-column type="expand">
          <template slot-scope="props">
<!--            {{props.row.billingLog}}-->
            <el-form label-position="left" class="demo-table-expand" inline>
              <div v-for="(obj,index) in props.row.billingLog" :key="index">
                <el-form-item  label="订单状态"><div>{{ obj.dictStatusName }}</div></el-form-item>
                <el-form-item  label="订单金额"><div>{{ obj.payMoney }}</div></el-form-item>
                <el-form-item  label="操作类型"><div>{{ obj.dictOperationTypeName }}</div></el-form-item>
                <el-form-item  label="操作人"><div>{{ obj.operator }}</div></el-form-item>
                <el-form-item  label="操作时间"><div>{{ obj.insertTime }}</div></el-form-item>
              </div>

            </el-form>
          </template>
        </el-table-column>
        <el-table-column prop="cardNum" label="我方业务号码" align="center" :fixed="$store.state.app.screenWidth<992?true:false" :width="$store.state.app.screenWidth<992?'130px':'auto'">
          <template slot-scope="scope">
            <span :style="{'color':scope.row.dictIsProblemOrder==='C_YES'?'red':''}">{{ scope.row.cardNum }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="loginName" label="代理账号" align="center" :width="$store.state.app.screenWidth<992?'130px':'auto'">
          <template slot-scope="scope">
            <span :style="{'color':scope.row.dictIsProblemOrder==='C_YES'?'red':''}">{{ scope.row.loginName }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="nickName" label="C端用户" align="center" :width="$store.state.app.screenWidth<992?'130px':'auto'">
          <template slot-scope="scope">
            <span
              :style="{'color':scope.row.dictIsProblemOrder==='C_YES'?'red':''}">{{ scope.row.nickName }}</span>
          </template>
        </el-table-column><!--el-table-column(-->
        <el-table-column v-if="checkPer('orderCtrl')&&(roleChar=='OEM_ADMIN'||roleChar=='OEM_OTHER')" prop="transactionId" label="支付流水号" align="center" width="$store.state.app.screenWidth<992?'150px':'240px'">
          <template slot-scope="scope">
            <span :style="{'color':scope.row.dictIsProblemOrder==='C_YES'?'red':''}">{{ scope.row.transactionId }}</span>
          </template>
        </el-table-column>

        <el-table-column prop="insertTime" label="提交时间" align="center" :width="$store.state.app.screenWidth<992?'130px':'auto'">
          <template slot-scope="scope">
            <span :style="{'color':scope.row.dictIsProblemOrder==='C_YES'?'red':''}">{{ scope.row.insertTime }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="dictPayTunnelName" label="付款通道" align="center" :width="$store.state.app.screenWidth<992?'130px':'auto'">
          <template slot-scope="scope">
            <span
              :style="{'color':scope.row.dictIsProblemOrder==='C_YES'?'red':''}">{{ scope.row.dictPayTunnelName }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="price" label="现金" align="center" :width="$store.state.app.screenWidth<992?'130px':'auto'">
          <template slot-scope="scope">
            <span :style="{'color':scope.row.dictIsProblemOrder==='C_YES'?'red':''}">{{ scope.row.price }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="oemCost" label="成本" align="center" :width="$store.state.app.screenWidth<992?'130px':'auto'">
          <template slot-scope="scope">
            <span :style="{'color':scope.row.dictIsProblemOrder==='C_YES'?'red':''}">{{ scope.row.oemCost }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="profitForAgent" label="利润" align="center" :width="$store.state.app.screenWidth<992?'130px':'auto'">
          <template slot-scope="scope">
            <span :style="{'color':scope.row.dictIsProblemOrder==='C_YES'?'red':''}">{{ scope.row.profitForAgent }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="setMealName" label="套餐" align="center" width="130px" :width="$store.state.app.screenWidth<992?'130px':'auto'">
          <template slot-scope="scope">
            <span :style="{'color':scope.row.dictIsProblemOrder==='C_YES'?'red':''}">{{ scope.row.setMealName }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="amount" label="连续充值次数" align="center" :width="$store.state.app.screenWidth<992?'130px':'auto'">
          <template slot-scope="scope">
            <span v-if="scope.row.amount&&scope.row.amount>0">{{ scope.row.amount }} 次</span>
            <span v-else>--</span>
          </template>
        </el-table-column>
        <el-table-column prop="dictIsPreStorageName" label="次月生效" align="center" :width="$store.state.app.screenWidth<992?'130px':'auto'">
          <template slot-scope="scope">
            <span
              :style="{'color':scope.row.dictIsProblemOrder==='C_YES'?'red':''}">{{ scope.row.dictIsPreStorageName }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="dictStatusName" label="状态" align="center" :width="$store.state.app.screenWidth<992?'130px':'auto'">
          <template slot-scope="scope">
            <span :style="{'color':scope.row.dictIsProblemOrder==='C_YES'?'red':''}">{{ scope.row.dictStatusName }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="isHide" label="订单是否已隐藏" align="center" :width="$store.state.app.screenWidth<992?'130px':'auto'" v-if="checkPer('hideOrderPer')">
          <template slot-scope="scope">
            <span :style="{'color':scope.row.isHide==='C_YES'?'red':''}" v-if="scope.row.isHide=='C_YES'">已隐藏</span>
            <span :style="{'color':scope.row.isHide==='C_YES'?'red':''}" v-if="scope.row.isHide!='C_YES'">未隐藏</span>
          </template>
        </el-table-column>
        <el-table-column v-has="'orderCtrl'" prop="dictStatus" label="操作" align="center">
          <template slot-scope="scope">
            <el-dropdown trigger="click">
              <div>
                <svg-icon class="el-dropdown-link" icon-class="operation"></svg-icon>
              </div>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item>
                  <el-button class="operation" type="text" v-has="'oprationStatusPer'" @click="doSomeAct(scope.row, 'updateState')" v-preventReClick>修改状态</el-button>
                </el-dropdown-item>
<!--                <el-dropdown-item>-->
<!--                  <el-button class="operation" type="text" v-has="'refundPer'" @click="doSomeAct(scope.row, 'refundOrder')" v-preventReClick>退款</el-button>-->
<!--                </el-dropdown-item>-->
                <el-dropdown-item>
                  <el-button class="operation" type="text" v-has="'retryPer'" @click="doSomeAct(scope.row, 'retryOrder')" v-preventReClick v-if="scope.row.dictStatus == 'USER_ORDER_RUNNING'">重试</el-button>
                </el-dropdown-item>
                <el-dropdown-item>
                  <el-button class="operation" type="text" v-has="'retryPer'" @click="doSomeAct(scope.row, 'retryRebate')" v-preventReClick>重试返佣</el-button>
                </el-dropdown-item>
                <el-dropdown-item v-show="scope.row.isHide!='C_YES'">
                  <el-button style="width: 100%;" class="operation" type="text" v-preventReClick @click="hideOrder(scope.row)" v-has="'hideOrderPer'" >隐藏订单</el-button>
                </el-dropdown-item>
                <el-dropdown-item v-show="scope.row.isHide=='C_YES'">
                  <el-button style="width: 100%;" class="operation" type="text" v-preventReClick @click="hideOrder(scope.row)" v-has="'hideOrderPer'" >取消隐藏</el-button>
                </el-dropdown-item>
<!--                <el-dropdown-item>-->
<!--                  <el-button class="operation" type="text" v-has="'deleteOrderFlowPer'" @click="doSomeAct(scope.row, 'deleteOrder')" v-preventReClick>删除订单流量</el-button>-->
<!--                </el-dropdown-item>-->
<!--                <el-dropdown-item>-->
<!--                  <el-button class="operation" type="text" v-has="'retryPer'" @click="doSomeAct(scope.row, 'updateOrderNo')" v-preventReClick>修改支付流水号</el-button>-->
<!--                </el-dropdown-item>-->
                <el-dropdown-item>
                  <el-button class="operation" type="text" v-has="'retryPer'" @click="doSomeAct(scope.row, 'openRemark')" v-preventReClick >查看备注</el-button>
                </el-dropdown-item>
                <el-dropdown-item v-show="scope.row.requestUrl">
                  <el-button class="operation" type="text" v-has="'retryPer'" @click="showUrlMessage(scope.row)" >查看请求地址/入参/回参</el-button>
                </el-dropdown-item>
                <el-dropdown-item >
                  <el-button class="operation" type="text" v-has="'refundPer'" @click="openNewDialog(scope.row)" >订单操作</el-button>
                </el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </template>
        </el-table-column>
      </el-table>
      <div :style="{'overflow-x': $store.state.app.screenWidth<992?'scroll':'none'}">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page.sync="currentPage"
          :page-size="pageSize"
          class="row-main-pager"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total" :page-sizes="[10,20,30,40]"
          background></el-pagination>
      </div>
    </div>
    <!--  弹窗：导出一级代理利润  -->
    <el-dialog
      title="导出一级代理利润"
      :visible.sync="exploreProfitDialog"
      width="30%"
      center>
      <div style="display: flex;justify-content: center;align-items: center">
        <span>请选择筛选条件：</span>
        <el-date-picker
          v-model="exploreProfit"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          format="yyyy 年 MM 月 dd 日"
          value-format="yyyy-MM-dd">
        </el-date-picker>
<!--        <el-cascader-->
<!--          v-model="exploreProfit"-->
<!--          :options="chooseOptions"-->
<!--          :props="{ expandTrigger: 'hover' }"-->
<!--          @change="handleChange"></el-cascader>-->
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="exploreProfitDialog = false">取 消</el-button>
        <el-button type="primary" @click="downloadProfit">确 定</el-button>
      </span>
    </el-dialog>
    <!--  弹窗：修改订单状态 / 退款 /修改订单状态-->
    <el-dialog
      :title="title"
      :visible.sync="updateOrderInfoDialog"
      width="40%"
      center>
      <div style="display: flex;flex-direction: column;justify-content: center;align-items: center">
        <div style="display: flex; color:red;justify-content: center;">{{ tipText }}</div>
        <div style="margin-top: 20px">
          <el-form :model="actForm" ref="actForm" :rules="actRule" label-position="right" label-width="120px">
            <el-form-item label="订单状态：" prop="orderStatus" v-if="actStatus=='updateState'">
              <el-radio-group v-model="actForm.orderStatus" size="small">
                <el-radio-button v-for="item in orderStatusOptions" :key="item.label" :label="item.label">{{ item.value }}</el-radio-button>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="退款比例：" prop="rate_money" v-if="actStatus=='refundOrder'">
              <el-input v-model="actForm.rate_money" :disabled="actForm.disabled"></el-input>
            </el-form-item>
            <el-form-item label="退佣金比例：" prop="rate_brokerage" v-if="actStatus=='refundOrder'">
              <el-input v-model="actForm.rate_brokerage" :disabled="actForm.disabled"></el-input>
            </el-form-item>
            <el-form-item label="支付流水号：" prop="tranId" v-if="actStatus=='updateOrderNo'">
              <el-input v-model="actForm.tranId" style="width: 300px"></el-input>
            </el-form-item>
          </el-form>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="resetActForm('actForm')">取 消</el-button>
        <el-button type="primary" @click="onSubmit('actForm')" >确 定</el-button>
      </span>
    </el-dialog>
    <!--  弹窗：订单备注  -->
    <el-dialog title="订单备注"  top="33vh" :visible.sync="showRemarkDialog" width="40%" center>
      <div style="height: 20vh;overflow-y: scroll">
        <el-table :data="orderRemarkList" :header-cell-style="{ 'background':$store.state.app.tableBgColor,'color':'#606266' }" v-loading.fullscreen="orderRemarkLoading"
                  element-loading-text="数据加载中" element-loading-spinner="el-icon-loading" element-loading-background="rgba(0, 0, 0, 0.2)">
          <el-table-column type="index" label="序号" width="150" align="center"></el-table-column>
          <el-table-column property="mark" label="备注信息" align="center">
            <template slot-scope="scope">
              <el-tooltip class="item" effect="dark" :content="scope.row.mark" placement="top">
                <span style="white-space:nowrap;  overflow: hidden;  text-overflow: ellipsis;">{{ scope.row.mark }}</span>
              </el-tooltip>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="showRemarkDialog = false">关  闭</el-button>
      </span>
    </el-dialog>
    <!--  弹窗：订单备注  -->
    <el-dialog title="查看请求地址/入参/回参"  top="20vh" :visible.sync="orderUrlDialog" width="40%" center>
      <div style="max-height: 50vh;overflow-y: scroll">
        <div style="font-weight: bold;margin-bottom: 10px;">请求地址：</div>
        <div style="width: 100%;line-height: 25px;margin-bottom: 20px;text-indent: 40px;">{{requestUrl}}</div>
        <div style="font-weight: bold;margin-bottom: 10px;">入参：</div>
        <div style="width: 100%;line-height: 25px;margin-bottom: 20px;text-indent: 40px;">{{requestParams}}</div>
        <div style="font-weight: bold;margin-bottom: 10px;">回参：</div>
        <div style="width: 100%;line-height: 25px;margin-bottom: 20px;text-indent: 40px;">{{responseData}}</div>
        <div style="font-weight: bold;margin-bottom: 10px;">耗时：</div>
        <div style="width: 100%;line-height: 25px;margin-bottom: 20px;text-indent: 40px;">{{executionTime}} 毫秒</div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="colseUrlMessage">关  闭</el-button>
      </span>
    </el-dialog>


    <!--  新弹窗：按比例退款 / 按金额退款 / 修改订单支付流水号 / 删除订单流量-->
    <el-dialog
      title=""
      :visible.sync="showNewDialog"
      :width="$store.state.app.screenWidth<500?'100%':'700px'"
      center>
      <el-card class="box-card">
        <div slot="header" class="clearfix">
          <span>订单操作</span>
          <el-button style="float: right; padding: 3px 0" type="text" @click="goToCardDetail">查看卡详情</el-button>
        </div>
        <el-form :model="newForm" ref="newForm" label-width="150px" :rules="newFormRules">
          <el-form-item label="卡号">
            {{row.cardNumber}}
          </el-form-item>
          <el-form-item label="卡状态">
            <el-button type="text" :loading="!row.dictMyCardStatusName"></el-button>
            {{row.dictMyCardStatusName}}
          </el-form-item>
          <el-form-item v-for="(domain, index) in row.list" :label="'流量使用情况第'+(index+1)+'个月'" :key="index">
            <div class="row_flow" :style="{'border':domain.flag?'1px dashed green':'1px dashed darkred'}">
              <div class="cloumn_flow" style="height: 25px;color:darkred" v-if="!domain.flag">已失效</div>
              <div class="cloumn_flow" style="height: 25px;" v-if="domain.flag">未失效</div>
              <div class="cloumn_flow">
                <div style="height: 25px">{{domain.allFlow}}</div>
                <div style="height: 25px">总量</div>
              </div>
              <div class="cloumn_flow">
                <div style="height: 25px">{{domain.usedFlow}}</div>
                <div style="height: 25px">已用</div>
              </div>
              <div class="cloumn_flow">
                <div style="height: 25px">{{domain.surplusFlowForSetMeal}}</div>
                <div style="height: 25px">剩余</div>
              </div>
            </div>
          </el-form-item>
          <el-form-item label="操作" prop="act">
            <el-radio-group v-model="newForm.act">
              <el-radio label="0" style="display: block;line-height: 25px" v-if="row.dictStatus!=='USER_ORDER_FREE_FLOW'&&row.dictStatus!=='USER_ORDER_CONVERT_FLOW'" >退款</el-radio>
              <el-radio label="1" style="display: block;line-height: 25px">删除订单流量</el-radio>
              <el-radio label="2" style="display: block;line-height: 25px">修改支付流水号</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="退款方式" prop="type" v-show="newForm.act==='0'&&row.dictStatus!=='USER_ORDER_FREE_FLOW'&&row.dictStatus!=='USER_ORDER_CONVERT_FLOW'">
            <el-radio-group v-model="newForm.type">
              <el-radio label="0" style="display: block;line-height: 25px" v-if="row.list&&row.list.length>0" >按推荐比例退款</el-radio>
              <el-radio label="1" style="display: block;line-height: 25px">按百分比退款</el-radio>
              <el-radio label="2" style="display: block;line-height: 25px">按金额退款</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="推荐退款比例" v-show="newForm.act=='0'&&newForm.type=='0'&&!row.text&&row.list&&row.list.length>0&&row.dictStatus!=='USER_ORDER_FREE_FLOW'&&row.dictStatus!=='USER_ORDER_CONVERT_FLOW'">{{row.refundNum}} %<span style="color:darkred;margin-left:20px">*退款比例仅供参考</span></el-form-item>
          <el-form-item label="推荐退款比例" v-show="newForm.act=='0'&&newForm.type=='0'&&row.text&&row.list&&row.list.length>0&&row.dictStatus!=='USER_ORDER_FREE_FLOW'&&row.dictStatus!=='USER_ORDER_CONVERT_FLOW'"><span v-if="row.text">{{row.text}}</span></el-form-item>
          <el-form-item label="原支付流水号" v-show="newForm.act=='2'">{{row.transactionId}}</el-form-item>
          <el-form-item label="新支付流水号" prop="tranId" v-show="newForm.act=='2'">
            <el-input v-model="newForm.tranId" style="width: 300px"></el-input>
          </el-form-item>
          <el-form-item label="退款比例" prop="rate_money" v-show="newForm.act==='0'&&newForm.type==='1'&&row.dictStatus!=='USER_ORDER_FREE_FLOW'&&row.dictStatus!=='USER_ORDER_CONVERT_FLOW'">
            <el-input v-if="" v-model="newForm.rate_money" :disabled="newForm.disabled"><template slot="append">%</template></el-input>
          </el-form-item>
          <el-form-item label="退款金额" prop="refund_money" v-show="newForm.act==='0'&&newForm.type==='2'&&row.dictStatus!=='USER_ORDER_FREE_FLOW'&&row.dictStatus!=='USER_ORDER_CONVERT_FLOW'">
            <el-input v-model="newForm.refund_money" :disabled="newForm.disabled"><template slot="append">元</template></el-input>
          </el-form-item>
          <el-form-item label="退佣金比例" prop="rate_brokerage" v-show="newForm.act==='0'&&row.dictStatus!=='USER_ORDER_FREE_FLOW'&&row.dictStatus!=='USER_ORDER_CONVERT_FLOW'">
            <el-input v-model="newForm.rate_brokerage" :disabled="newForm.disabled"><template slot="append">%</template></el-input>
          </el-form-item>
<!--          <el-form-item label="退佣金金额" prop="refund_brokerage" v-show="newForm.act=='0'&&newForm.type=='2'">-->
<!--            <el-input v-model="newForm.refund_brokerage" :disabled="newForm.disabled"></el-input>-->
<!--          </el-form-item>-->
        </el-form>

      </el-card>
      <span slot="footer" class="dialog-footer">
        <el-button @click="showNewDialog = false">取 消</el-button>
        <el-button type="primary" @click="newSubmit" >确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import {
  getLoginName,           //查询代理账号
  initAccountSelect,      //通道下拉列表
  initSetMealHeadSelect,  //套餐大类下拉列表
  initSetMealSelect,      //套餐小类下拉列表
  customerOrderStatistics,//订单统计
  orderManagement,        //订单列表
  downLoadCutomerOrder,   //数据导出
  selectOrderAllRemark,   //查询订单备注
  updateOrderStatus,      //修改订单状态
  updateTransactionId,    //修改支付流水号
  backUserMoneyByOrderId, //重试返佣
  deleteOrderFlow,        //删除订单流量
  refreshOrder,           //重试
  orderRefundCheck,       //查询退款订单是否为第三方订单，是否在有效期之内
  orderBilling,           //订单变更日志
  customerRefundForPrice, //订单退款(4-15更新)
  selectAgentProfit, getCardFlowInfo,      //导出一级代理例如
  checkOrderFlow,         //查询当前订单流量使用情况
  hideOrder,              //隐藏订单
  getProfit //获取利润什么的
} from '@/api/getData'
export default {
  name: 'newIndex',
  data(){
    return{
      roleChar: '',             //登录者身份
      loginNames: [],           //代理账号下拉
      accountOptions: [],       //通道下拉
      dictStatusSelect: [       //订单状态下拉
        {
          value: '',
          label: '请选择订单状态'
        },
        {
          value: 'USER_ORDER_WAIT_PAY',
          label: '等待付款'
        },
        {
          value: 'USER_ORDER_HAVE_PAY',
          label: '已经付款'
        },
        {
          value: 'USER_ORDER_WAIT_GIVE',
          label: '待充送'
        },
        {
          value: 'REFUND_SUCCESS',
          label: '退款成功'
        },
        {
          value: 'USER_ORDER_FREE_FLOW',
          label: '赠送流量'
        },
        {
          value: 'USER_ORDER_CONVERT_FLOW',
          label: '兑换流量'
        },
        {
          value: 'USER_ORDER_RUNNING',
          label: '正在进行'
        },{
          value: 'TRANS_FAIL',
          label: '订单失败'
        },

      ],  //订单状态下拉
      setMealHeadOptions: [],   //套餐大类下拉
      setMealOptions: [],       //套餐小类下拉
      dictIsPreStorageOptions: [ //订单是否次月生效
        {
          value: '',
          label: '请选择是否次月生效'
        },
        {
          value: 'YES',
          label: '是'
        },
        {
          value: 'NO',
          label: '否'
        }
      ],//订单是否次月生效下来
      chooseOptions: [          //一级代理利润导出条件级联
        {
          value: '1',
          label: '年份',
          children: [
            {
              value: 'YEAR',
              label: '今年'
            },
            {
              value: 'LAST_YEAR',
              label: '去年'
            }
          ]
        },
        {
          value: '2',
          label: '季度',
          children: [
            {
              value: 'FIRST_QUARTER',
              label: '第一季度'
            },
            {
              value: 'SECOND_QUARTER',
              label: '第二季度'
            },
            {
              value: 'THIRD_QUARTER',
              label: '第三季度'
            },
            {
              value: 'FOURTH_QUARTER',
              label: '第四季度'
            }
          ]
        },
        {
          value: '3',
          label: '月',
          children: [
            {
              value: 'JANUARY',
              label: '一月'
            },
            {
              value: 'FEBRUARY',
              label: '二月'
            },
            {
              value: 'MARCH',
              label: '三月'
            },
            {
              value: 'APRIL',
              label: '四月'
            },
            {
              value: 'MAY',
              label: '五月'
            },
            {
              value: 'JUNE',
              label: '六月'
            },
            {
              value: 'JULY',
              label: '七月'
            },
            {
              value: 'AUGUST',
              label: '八月'
            },
            {
              value: 'SEPTEMBER',
              label: '九月'
            },
            {
              value: 'OCTOBER',
              label: '十月'
            },
            {
              value: 'NOVEMBER',
              label: '十一月'
            },
            {
              value: 'DECEMBER',
              label: '十二月'
            }
          ]
        },
      ],    //一级代理利润导出条件级联
      form:{
        loginName: '',          //代理账号
        cardNum: '',            //业务号码
        rechargeAmount: '',     //连续充值次数
        accountId: '',          //通道id
        dictStatus: 'USER_ORDER_HAVE_PAY',         //订单状态(默认值：已付款)
        setMealHeadId: '',      //套餐大类id
        setMealId: '',          //套餐小类id
        transactionId: '',      //交易流水号
        dictIsPreStorage: '',   //次月生效
        insertTime: '',         //提交时间
      },
      exploreProfitDialog: false,//导出一级代理利润弹窗
      exploreProfit: '',        //导出一级代理利润条件
      profitForAgentSum: '--',  //利润
      mineCostSum: '--',        //成本
      priceSum: '--',           //销售金额
      orderCount: '--',         //订单数
      isAllOrder: true,         //全部 or 直属订单
      tableData: [],            //订单列表数据
      tableLoading: false,      //数据加载
      currentPage: 1,
      pageSize: 10,
      ascs: [],
      descs: [],
      total: 0,
      showRemarkDialog: false,    //打开备注弹窗
      orderRemarkList: [],        //备注列表
      orderRemarkLoading:'',      //订单加载loading
      pagekey: '',                //防止重复提交
      updateOrderInfoDialog: false,//打开修改订单状态弹窗
      orderId: '',                //订单id
      actStatus: '',              //订单操作类型
      title: '',                  //订单操作弹窗名称
      tipText: '',                //提示文字
      orderStatusOptions: [       //订单状态
        { value: '待充送', label: '1' },
        { value: '已付款', label: '2' },
        { value: '待付款', label: '3' },
        // { value: '次月生效', label: '4' },
        // { value: '本月生效', label: '5' },
        { value: '退款成功', label: '6' },
      ],  //订单状态
      actForm: {
        orderStatus: '',          //订单状态
        rate_money: 100,          //订单退款比例
        rate_brokerage: 100,      //订单返佣比例
        tranId: '',               //订单流水号
        disabled: null,           //进行中订单显示true 退款只能100%退款
      },
      actRule: {
        orderStatus: [ { required: true, message: '请选择订单状态', trigger: 'change' }],
        rate_money: [
          { required: true, message: '请填写订单退款比例', trigger: 'blur'},
          { pattern: /^100|(\d){1,2}|[0]\.\d{1,2}|[1-9]{1}[0-9]{0,1}$/,message: '格式：1 - 100的整数', trigger: 'blur'},
        ],
        rate_brokerage: [
          { required: true, message: '请填写订单退佣金比例', trigger: 'blur'},
          { pattern: /^100|(\d){1,2}|[0]\.\d{1,2}|[1-9]{1}[0-9]{0,1}$/,message: '格式：1 - 100的整数', trigger: 'blur'},
        ],
        tranId: [
          { required: true, message: '请修改支付流水号', trigger: 'change' }
        ],
      },
      newFormRules: {
        rate_money: [
          { required: true, message: '请填写订单退款比例', trigger: 'blur'},
          { pattern: /^(0|100|(\d|[1-9]\d)(\.\d{1,2})?)$/,message: '格式：0 - 100,最多两位小数,不可以输入负数', trigger: 'blur'},
        ],
        rate_brokerage: [
          { required: true, message: '请填写订单退佣金比例', trigger: 'blur'},
          { pattern: /^(0|100|(\d|[1-9]\d)(\.\d{1,2})?)$/,message: '格式：0 - 100,最多两位小数,不可以输入负数', trigger: 'blur'},
        ],
        refund_money: [
          { required: true, message: '请填写订单退款金额', trigger: 'blur'},
          { pattern: /^(([1-9]{1}\d*)|(0{1}))(\.\d{1,2})?$/,message: '格式：最多两位小数,不可以输入负数', trigger: 'blur'},
        ],
        tranId: [
          { required: true, message: '请修改支付流水号', trigger: 'change' }
        ],
      },
      orderUrlDialog: false,
      requestUrl: '',
      requestParams: '',
      responseData: '',
      executionTime: '',
      row: {},
      showNewDialog: false,
      newForm:{
        act: '0',
        tranId: '',
        type: '0',
        rate_money: '',
        refund_money: '',
        rate_brokerage: '',
        // refund_brokerage: '',
        disabled: false,
      },
    }
  },
  mounted(){
    this.roleChar = localStorage.getItem('roleChar');
    this.getAccountList();
    this.initSetMealHeadList();
    this.initData();
  },
  methods:{
    async doSomeAct(item, state){
      this.actStatus = state;
      this.orderId = item.id;
      this.pagekey = await this.$getPageKey();
      switch (state){
        case 'updateState':
          this.title = '修改订单状态';
          this.updateOrderInfoDialog = true;
          this.tipText = `【※修改订单状态为高风险操作※】请谨慎操作！！！！当前订单状态：${ item.dictStatusName }`
          break;
        case 'refundOrder':
          this.title = '订单退款';
          this.updateOrderInfoDialog = true;
          this.actForm.rate_money = 100;
          this.actForm.rate_brokerage = 100;
          this.actForm.disabled = item.dictStatus=='USER_ORDER_RUNNING'?true:false;
          this.tipText = '【※订单退款为高风险操作※】请谨慎操作！！！！'
          break;
        case 'retryOrder':
          if(item.isHide=='C_YES'){
            this.$message.error('当前订单隐藏状态下不支持重试功能');
            return false;
          }
          this.$confirm('重试后会为此卡添加流量，确认重新刷新么？', '※高风险操作 【重试】※ ', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            refreshOrder({id:this.orderId,pagekey:this.pagekey}).then(v => {
              backUserMoneyByOrderId({id:this.orderId}).then(v => {
                if (v.code === 10000) {
                  this.$message.success("操作成功!")
                }
                this.initData()
              })
            })
          }).catch(() => {
            this.$message({
              type: 'info',
              message: '已取消操作'
            });
          });
          break;
        case 'retryRebate'://重试返佣
          if(item.isHide=='C_YES'){
            this.$message.error('当前订单隐藏状态下不支持重试返佣功能');
            return false;
          }
          this.$confirm('1.待付款订单无法重试；\r\n2.该笔订单存在返佣记录无法重试。', '※高风险操作 【重试返佣】※ ', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            backUserMoneyByOrderId({id:this.orderId}).then(v => {
              if (v.code === 10000) {
                this.$message.success("操作成功!")
              }
              this.initData()
            })
          }).catch(() => {
            this.$message({
              type: 'info',
              message: '已取消操作'
            });
          });
          break;
        case 'deleteOrder':
          this.$confirm('确定立即删除订单流量么', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            this.doDeleteOrderFlow()
          }).catch(() => {
            this.$message({
              type: 'info',
              message: '已取消操作'
            });
          });
          // this.$confirm('确定立即删除订单流量么？', '提示', {
          //   confirmButtonText: '确定',
          //   cancelButtonText: '取消',
          //   type: 'warning'
          // }).then(() => {
          //   this.doDeleteOrderFlow()
          // }).catch(() => {
          //   this.$message({
          //     type: 'info',
          //     message: '已取消操作'
          //   });
          // });
          break;
        case 'updateOrderNo':
          this.title = '修改支付流水号';
          this.tipText = '原支付流水号：'+item.transactionId;
          this.actForm.tranId = item.transactionId;
          this.updateOrderInfoDialog = true;
          break;
        case 'openRemark':
          this.showRemarkDialog = true;
          this.orderRemarkList = [];
          this.orderRemarkLoading = true;
          let orderRemarkList = await selectOrderAllRemark({id: item.id});
          if(orderRemarkList.data){
            orderRemarkList.data.map(item=>{
              this.orderRemarkList.push(item);
            })
          }
          this.orderRemarkLoading = false;
          break;
      }

    },
    newSubmit(){
      if(this.newForm.act == '1'){  //删除订单流量
        this.$confirm('确定立即删除订单流量么', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.doDeleteOrderFlow()
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消操作'
          });
        });
      }
      else if(this.newForm.act == '2'){//修改支付流水号
        this.doUpdateTransId();
      }
      else if(this.newForm.act == '0'){//退款
        this.doOrderRefund();
      }
    },
    showUrlMessage(item){
      this.requestUrl = item.requestUrl;
      this.requestParams = item.requestParams;
      this.responseData = item.responseData;
      this.executionTime = item.executionTime;
      this.orderUrlDialog = true;
    },
    colseUrlMessage(){
      this.requestUrl = '';
      this.requestParams = '';
      this.responseData = '';
      this.executionTime = '';
      this.orderUrlDialog = false;
    },
    resetActForm(form){
      this.$refs[form].resetFields();
      this.updateOrderInfoDialog = false
    },
    onSubmit(form){
      this.$refs[form].validate((valid)=>{
        if(valid){
          switch (this.actStatus){
            case 'updateState':     //修改订单状态
              this.doUpdateOrderStatus();
              break;
            case 'refundOrder':     //订单退款
              this.doOrderRefund();
              break;
            case 'updateOrderNo':   //修改订单号
              this.doUpdateTransId();
              break;
          }
        }
      })
    },
    async openNewDialog(row){
      this.pagekey = await this.$getPageKey();
      this.newForm = {
        act: row.dictStatus=='USER_ORDER_FREE_FLOW'||row.dictStatus=='USER_ORDER_CONVERT_FLOW'?'1':'0',
        tranId: '',
        type: '1',
        rate_money: '100',
        refund_money: row.dictStatus=='USER_ORDER_RUNNING'?row.payMoney:'',
        rate_brokerage: '100',
        disabled: row.dictStatus=='USER_ORDER_RUNNING'?true:false,

      }
      //查当前订单下流量已使用情况  注意分月到账的套餐处理
      checkOrderFlow({id: row.id,cardId:row.cardId}).then(v => {
        this.row = {
          id: row.id,
          cardId: row.cardId,
          cardNumber: row.cardNumber,
          transactionId: row.transactionId,
          dictStatus: row.dictStatus,
          usedFlow: '0MB',
          allFlow: '0MB',
          cardFlowActUsed: '0MB',
          surplusFlowForSetMeal: '0MB',
          dictMyCardStatusName: '',
          refundNum: 0,
          list: [],
          text: '',
          third: false,
        };
        if (v.data) {
          this.row.dictMyCardStatusName = v.data.dictChannelCardStatusName?v.data.dictChannelCardStatusName:'未知状态'; // 卡状态
          this.row.third = v.data.thirdName?true:false;
          this.row.text = this.row.third?'具体退款比例请咨询上游':'';
          for(let item of v.data.cardFlowList){
            let obj = {};
            obj.allFlow = item.mb ? this.$toGB.exe(item.mb) : '0MB';
            obj.usedFlow = item.virtualUsedMb ? this.$toGB.exe(item.virtualUsedMb) : '0MB';
            obj.all = item.mb * 1;
            obj.used = item.virtualUsedMb * 1;
            obj.surplus = obj.all - obj.used;
            obj.surplusFlowForSetMeal = obj.surplus ? this.$toGB.exe(obj.surplus) : '0MB';
            obj.sumFlow = obj.flag?obj.allFlow:obj.usedFlow;
            obj.dictMonthlyPayment = item.dictMonthlyPayment;//是否分月到账 YES NO
            obj.flag = item.isvalid;//true 已过期 false未过期
            obj.date = item.beginTime;

            this.row.list.push(obj);
          }

          let percent = 100;
          if(row.dictStatus=='USER_ORDER_RUNNING'||row.dictStatus=='USER_ORDER_WAIT_GIVE'){
            this.row.refundNum = 100;
          }
          else{
            if(this.row.list.length>1){
              let everyPercent = parseInt(100 / this.row.list.length);
              for(let item of this.row.list){
                if(item.flag){
                  if(item.surplus>0){
                    let a = parseFloat(item.used  / item.all).toFixed(2);
                    let b = a * everyPercent;
                    percent = percent - b;
                  }
                }
                else{
                  percent = percent - everyPercent;
                }
              }
            }
            if(this.row.list.length==1){
              if(this.row.list[0].flag){
                let a = parseInt(this.row.list[0].used * 100 / this.row.list[0].all);
                percent = percent - a;
              }
              else{
                percent = 0;
              }
            }
            this.row.refundNum = percent;
          }

          // this.row.usedFlow = v.data.usedFlow ? this.$toGB.exe(v.data.usedFlow) : '0MB';
          // this.row.allFlow = v.data.allFlow ? this.$toGB.exe(v.data.allFlow) : '0MB';
          // this.row.cardFlowActUsed = v.data.cardFlowActUsed ? this.$toGB.exe(v.data.cardFlowActUsed) : '0MB';
          // this.row.surplusFlowForSetMeal = v.data.surplusFlowForSetMeal ? this.$toGB.exe(v.data.surplusFlowForSetMeal) : '0MB';

          // let a = v.data.usedFlow?v.data.usedFlow*1:0;
          // let a = v.data.cardFlowActUsed?v.data.cardFlowActUsed*1:0;
          // let b = v.data.allFlow?v.data.allFlow*1:0;
          // let d = b - a
          // let c = b==0?0:d*100/b;
          // // console.log('a='+a+' b='+b+' d='+d+' c='+c)
          // this.row.refundNum = c==0?'0':parseInt(c);

          // this.row.refundNum = row.dictStatus=='USER_ORDER_RUNNING'?100:this.row.refundNum;
        }
        this.$forceUpdate();
        this.showNewDialog = true;

      })
    },
    goToCardDetail(){
      const {href} = this.$router.resolve(
        {
          path: '/card/cardDetailIndex',
          query: {cardId: this.row.cardId, cardNumber: this.row.cardNumber}}
      )
      window.open(href, '_blank')
      // this.$router.push({path: '/card/cardDetailIndex', query: {cardId: this.row.cardId, cardNumber: this.row.cardNumber}});
    },
    //删除订单流量
    async doDeleteOrderFlow(){
      // let res = deleteOrderFlow({id: this.row.id,pagekey:this.pagekey})
      deleteOrderFlow({id: this.row.id,pagekey:this.pagekey}).then(res=>{
        if (res.code==10000) {
          this.showNewDialog = false;
          this.$message({
            message: '操作成功!',
            type: 'success'
          });
        }
      })
    },
    //弹窗--修改订单状态
    doUpdateOrderStatus(){
      let status = this.orderStatusOptions.filter(item=>{
        return item.label == this.actForm.orderStatus;
      })
      this.$confirm('是否继续将当前订单状态修改为：'+status[0].value+ ' ?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async () => {
        await updateOrderStatus({id: this.orderId, dictStatus: this.actForm.orderStatus}, {
          pagekey: this.pagekey
        }).then(v => {
          this.updateOrderInfoDialog = false;
          if (v._result) {
            this.$message.success("更改成功!");
            this.initData()
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消操作'
        });
      });
    },
    //弹窗--订单退款
    async doOrderRefund(){
      let check = await orderRefundCheck({id:this.row.id});
      if(check._result){
        let tipText = '';
        if(check.data.isThirdFlag){
          tipText = '该订单为第三方订单，'
        }
        if(check.data.notFindDueTime){
          tipText = '该订单未检索到有效期，'
        }
        if(check.data.errorMessage==''||check.data.errorMessage==undefined){
          if(tipText!=''){
            this.$confirm(`${tipText}是否继续对当前订单执行退款？`, '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            }).then(() => {
              this.doRefund()
            }).catch(() => {

            });
          }
          else if(tipText==''){
            this.doRefund()
          }
        }
        else if(check.data.errorMessage!=''&&check.data.errorMessage!=undefined){
          this.$alert(`${tipText}${check.data.errorMessage}`, '提示', {
            confirmButtonText: '确定',
            callback: action => {
              this.showNewDialog = false;
            }
          });
        }
      }
    },
    async doRefund(){
      let pagekey = await this.$getPageKey();
      this.$confirm('确认退款么?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let rate_money = '';
        if(this.newForm.type=='0')rate_money = this.row.refundNum;
        if(this.newForm.type=='1')rate_money = this.newForm.rate_money;
        customerRefundForPrice({
          proportion: rate_money,
          customerOrderId: this.row.id,
          backUserProportion: this.newForm.rate_brokerage,
          refund: this.newForm.type=='2'?this.newForm.refund_money:''
        }, {pagekey}).then(v => {
          this.showNewDialog = false;
          if (v._result) {
            this.$message.success("请到退款记录中查看");
            this.initData();
          }
        })
      }).catch(() => {

      });
    },
    //弹窗--修改订单支付流水号
    doUpdateTransId(){
      this.$confirm('是否继续将当前订单支付流水号修改为：'+ this.newForm.tranId + ' ?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        updateTransactionId(({
          id: this.row.id,
          transactionId: this.newForm.tranId,
        })).then(res => {
          // this.showEditeOrderNoDialogue = false;
          this.showNewDialog = false;
          this.initData()
        });
        // this.updateOrderInfoDialog = false;
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消操作'
        });
        this.updateOrderInfoDialog = false;
      });

    },
    async initData() {
      let startTime = null
      let endTime = null
      if (this.form.insertTime&& this.form.insertTime.length==2) {
        startTime = this.form.insertTime[0];
        endTime = this.form.insertTime[1];
      }
      this.tableLoading = true;
      const returnData = await orderManagement({
          beginTime: startTime,                           //起始时间
          endTime: endTime,                               //结束时间
          cardNum: this.form.cardNum,                     //业务号码
          loginName: this.form.loginName,                 //代理账号
          dictStatus: this.form.dictStatus,               //订单状态
          accountId: this.form.accountId,                 //通道id
          setMealHeadId: this.form.setMealHeadId,         //套餐大类id
          setMealId: this.form.setMealId,                 //套餐小类id
          dictIsPreStorage: this.form.dictIsPreStorage,   //是否次月生效
          transactionId: this.form.transactionId,         //交易流水号
          amount: this.form.rechargeAmount,               //连续充值次数
          isAllOrder: this.isAllOrder,
          page: {
            current: this.currentPage + '',
            size: this.pageSize + '',
            ascs: this.ascs,
            descs: this.descs
          }
        },
        {
          obj: this,
          key: 'tableLoading'
        })
      this.tableData = []
      if (returnData._result) {
        this.total = returnData.data.total
        for(let item of returnData.data.records){
          item.billingLog = [];
          item.transProfitForAgent = item.profitForAgent
          item.profitForAgent = "计算中..."
          item.nickName = "查询中..."
          if(!item.oemCost){
            item.oemCost = "查询中..."
          }
          this.tableData.push(item);
        }
        // this.tableData = new Array(...returnData.data.records);
      }
      this.tableLoading = false;
      if(this.tableData){
        for(let item of this.tableData){
          getProfit({
            id:item.id,
            profitForAgent:item.transProfitForAgent
          }).then(res=>{
            if(res.data){
              //item.price = res.data.price
              //item.oemCost = res.data.oemCost
              item.profitForAgent = res.data.profitForAgent
              item.nickName = res.data.nickName
              if(res.data.loginName){
                item.loginName =res.data.loginName
              }
              if(res.data.oemCost){
                item.oemCost =res.data.oemCost
              }
            }
          })

          orderBilling({
            id: item.id
          }).then(res=>{
            if(res.data){
              item.billingLog = res.data;
            }
          })
        }
      }
      this.countTotal();
    },
    //隐藏订单
    hideOrder(row){

      let tip = row.isHide=='C_YES'?'此操作将取消隐藏当前订单, 是否继续':'此操作将隐藏当前订单, 是否继续';
      this.$confirm(`${tip}`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async () => {
        this.tableLoading = true;
        let obj = await hideOrder({
          id: row.id,
          isHide: row.isHide=='C_YES'?'C_NO':'C_YES'
        })
        this.tableLoading = false;
        if(obj.code==10000){
          this.$message({
            type: 'success',
            message: '操作执行成功!'
          });
          this.initData()
        }
        else{
          this.$message.error('操作执行失败')
        }

      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消操作'
        });
      });
    },
    handleSizeChange(val) {
      this.pageSize = val;
      this.currentPage = 1;
      this.initData()
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.initData()
    },
    changeAllStatus() {
      this.isAllOrder = true;
      this.initData();
    },
    changeSectionStatus() {
      this.isAllOrder = false;
      this.initData();
    },
    //查询
    search() {
      let reg = /^[1-9]\d*$/;
      if(this.form.rechargeAmount&&!reg.test(this.form.rechargeAmount)){
        this.$message.error('请修改连续充值次数');
        return false
      }
      this.initData()
    },
    //重置
    clearForm(formName) {
      this.$refs[formName].resetFields();
    },
    //打开备注弹窗
    async openRemarkDialog(row){
      this.showRemarkDialog = true;
      this.orderRemarkList = [];
      this.orderRemarkLoading = true;
      let orderRemarkList = await selectOrderAllRemark({id: row.id});
      if(orderRemarkList.data){
        orderRemarkList.data.map(item=>{
          this.orderRemarkList.push(item);
        })
      }
      this.orderRemarkLoading = false;
    },
    //订单统计
    async countTotal() {
      let startTimeForStatistics = null
      let endTimeForStatistics = null
      if (this.form.insertTime && this.form.insertTime.length==2) {
        startTimeForStatistics = this.form.insertTime[0]
        endTimeForStatistics = this.form.insertTime[1]
      }
      this.profitForAgentSum = ""
      this.mineCostSum = ""
      this.priceSum = ""
      this.orderCount = ""
      const returnData = await customerOrderStatistics({
        beginTime: startTimeForStatistics,
        endTime: endTimeForStatistics,
        cardNum: this.form.cardNum,
        loginName: this.form.loginName,
        dictStatus: this.form.dictStatus,
        accountId: this.form.accountId,
        setMealHeadId: this.form.setMealHeadId,
        setMealId: this.form.setMealId,
        dictIsPreStorage: this.form.dictIsPreStorage,
        transactionId: this.form.transactionId,
        amount: this.form.rechargeAmount,
        isAllOrder: this.isAllOrder
      })
      if (returnData._result) {
        if (returnData.data != null) {
          this.profitForAgentSum = returnData.data.profitForAgentSum
          this.mineCostSum = returnData.data.mineCostSum
          this.priceSum = returnData.data.priceSum
          this.orderCount = returnData.data.orderCount
        }
      }
    },
    //文件下载
    exlDownload() {
      let startTime = null
      let endTime = null
      if (this.form.insertTime !== '' && this.form.insertTime != null) {
        startTime = this.form.insertTime[0];
        endTime = this.form.insertTime[1];
      }
      downLoadCutomerOrder({
        beginTime: startTime,
        endTime: endTime,
        cardNum: this.form.cardNum,
        loginName: this.form.loginName,
        dictStatus: this.form.dictStatus,
        accountId: this.form.accountId,
        setMealHeadId: this.form.setMealHeadId,
        setMealId: this.form.setMealId,
        dictIsPreStorage: this.dictIsPreStorage,
        transactionId: this.form.transactionId,
        amount: this.form.rechargeAmount,
        isAllOrder: this.isAllOrder,
      })
      this.$confirm('正在查询中，是否立即前往任务中心查看结果?', '提示', {
        confirmButtonText: '前往任务中心',
        cancelButtonText: '留在当前页',
        type: 'warning'
      }).then(() => {
        this.$router.push({
          path: '/mission/mission'
        })
      }).catch(() => {

      });
    },
    //导出一级代理利润
    downloadProfit(){
      if (!this.exploreProfit||this.exploreProfit.length==0) {
        this.$message.error("请选择一个时间点")
        return
      }
      let start = '';
      let end = '';
      if(this.exploreProfit){
        start = this.exploreProfit[0];
        end = this.exploreProfit[1];
      }
      selectAgentProfit({
        startTime: start,
        finalTime:end
      })
      this.$confirm('正在查询中，是否立即前往任务中心查看结果?', '提示', {
        confirmButtonText: '前往任务中心',
        cancelButtonText: '留在当前页',
        type: 'warning'
      }).then(() => {
        this.$router.push({
          path: '/mission/mission'
        })
      }).catch(() => {
        this.exploreProfitDialog = false;
      });
    },
    //查询代理账号
    async querySearch(queryString, cb) {
      let a = await getLoginName({
        loginname: this.form.loginName
      })
      if (a._result) {
        this.loginNames = [];
        for (let i = 0; i < a.data.length; i++) {
          this.loginNames.push({'value': a.data[i]})
        }
      }

      var loginNames = this.loginNames;
      //var results = queryString ? loginNames.filter(this.createFilter(queryString)) : loginNames;
      // 调用 callback 返回建议列表的数据
      cb(loginNames);
    },
    //获取通道下拉列表
    async getAccountList(){
      const returnData = await initAccountSelect({})
      this.accountOptions = []
      if (returnData._result) {
        for (let item of returnData.data) {
          const obj = {}
          obj.value = item.id;
          obj.label = item.accountName;
          this.accountOptions.push(obj)
        }
      }
    },
    //加载套餐大类列表
    async initSetMealHeadList(){
      let returnData = await initSetMealHeadSelect({})
      this.setMealHeadSelect = []
      if (returnData._result) {
        for (let item of returnData.data) {
          let obj = {}
          obj.value = item.id;
          obj.label = item.name;
          this.setMealHeadOptions.push(obj)
        }
      }
    },
    //切换套餐大类搜索套餐小类列表
    async initSetMealList(){
      this.form.setMealId = ''
      this.setMealSelect = [];
      this.setMealOptions = [];
      const returnData = await initSetMealSelect({
        headId: this.form.setMealHeadId
      })
      if (returnData._result) {
        for (let item of returnData.data) {
          let obj = {}
          obj.value = item.id;
          obj.label = item.mealName;
          this.setMealOptions.push(obj);
        }
      }
    },
    //获取导出条件值
    handleChange(value) {
      console.log(value);
    },
    //刷新数据
    refreshPage() {
      this.currentPage = 1;
      this.initData();
    },
  }
}
</script>
<style scoped lang="scss">
.row-block-ddd {
  height: 35px;
  line-height: 35px;
  /*margin: 0 calc(50% - 400px);*/
  position: relative;
  font-size: 14px;
  display: inline-block;
  float: right;
}
.row_top_item {
  display: inline-flex;
  align-items: center;
  margin-right: 10px;
}
.row-data {
  min-width: 200px;
  position: relative;
  border-right: 1px solid #ebebeb;
  display: inline-flex;
  justify-content: center;

  .echo {
    color: var(--lightBg) !important;
  }
}
.row_flow{
  width: auto;
  display: flex;
  justify-content: flex-start;
  align-items: center;
  border: 1px dashed #e6e6e6;
  padding: 0 10px;
}
.cloumn_flow{
  width: 120px;
  height: 60px;
  line-height: 25px;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
}
</style>
